package com.freak.wanandroid.model.home;

import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.freak.wanandroid.R;
import com.freak.wanandroid.base.activity.BaseLifecycleActivity;
import com.freak.wanandroid.model.home.adapter.SpecialSubscriptionListAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: freak
 * @date: 2022/9/21
 */
public class SpecialSubscriptionActivity extends BaseLifecycleActivity<HomePageViewModel> {
    private RecyclerView mRecycleViewSpecialSubscription;

    private SpecialSubscriptionListAdapter mSpecialSubscriptionListAdapter;

    private List<MultiItemEntity> mMultiItemEntities;

    private TextView mTextView;

    @Override
    protected int getLayout() {
        return R.layout.activity_special_subscription;
    }

    @Override
    protected void initEventAndData() {

    }

    @Override
    protected void onDestroyRelease() {

    }

    @Override
    protected void initView() {
        setTitleString("状态订阅");
        setBackPress();
        mMultiItemEntities = new ArrayList<>();
        mRecycleViewSpecialSubscription = getViewById(R.id.recycleViewSpecialSubscription);
        mSpecialSubscriptionListAdapter = new SpecialSubscriptionListAdapter(mMultiItemEntities, mActivity);
        mRecycleViewSpecialSubscription.setLayoutManager(new LinearLayoutManager(mActivity));
        mSpecialSubscriptionListAdapter.bindToRecyclerView(mRecycleViewSpecialSubscription);
        mSpecialSubscriptionListAdapter.setOnChildrenClickListener((type, itemType, systemClassChildrenEntity) -> mViewModel.updateSpecialSubscriptionInfo(systemClassChildrenEntity, type == 0 ? 0 : 1));
        mRecycleViewSpecialSubscription.setAdapter(mSpecialSubscriptionListAdapter);
    }

    @Override
    protected void onCreateLoadData() {

    }

    @Override
    protected void onResumeLoadData() {
        mViewModel.isGetList = true;
        mViewModel.getSpecialSubscriptionList();
    }

    @Override
    protected void dataObserver() {
        mViewModel.mListMutableLiveData.observe(this, multiItemEntities -> {
            mMultiItemEntities.clear();
            mMultiItemEntities.addAll(multiItemEntities);
            mSpecialSubscriptionListAdapter.notifyDataSetChanged();
        });
    }
}
